#!/bin/bash

HOSTS=(ciclope wolverine magneto hulk colossus tempestade demolidor vampira gambit elektra anjo justiceiro noturno x-men venon)
SERVER="/home/grupo11sd/rpc/rpc_param_server"
CLIENT="/home/grupo11sd/rpc/rpc_param_client"

kill_all() {
	for i in `seq 0 13`; do
		ssh -f ${HOSTS[$i]} "/usr/bin/killall rpc_param_server rpc_param_client >/dev/null 2>/dev/null" >/dev/null 2>/dev/null
	done 
}

kill_all

rm -rf /home/grupo11sd/rpc/logs

mkdir /home/grupo11sd/rpc/logs

for j in `seq 0 14`; do
	mkdir /home/grupo11sd/rpc/logs/log$j/
done

ssh -f x-men "$SERVER > /home/grupo11sd/rpc/logs/servidor.log 2>&1"

for j in `seq 0 14`; do
	for i in `seq 0 11`; do
		ssh -f ${HOSTS[$i]} "$CLIENT > /home/grupo11sd/rpc/logs/log$j/${HOSTS[$i]}.log 2>&1"
	done
	sleep 10
done

rm -rf resultados.zip

zip -r resultados logs

scp -P 2447 resultados.zip luis@localhost:~/Desktop/Resultados/

kill_all
